home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1996 February / EnigmA AMIGA RUN 04 (1996)(G.R. Edizioni)(IT)[!][issue 1996-02][Skylink CD III].iso / earcd / faq / kjvcbibl.lha / cbible / rexx / message.thnkr < prev    next >
Text File  |  1993-03-18  |  9KB  |  236 lines

  1. /******************************************************************
  2. *                                                                 *
  3. *    Thinker Macro to process a captured BBS message file         *
  4. *    You will certainly have to customize this for your BBS       *
  5. *                                                                 *
  6. *    This macro extracts messages as branches under the branch    *
  7. *    labeled "new".  Subsequently you can sort the messages       *
  8. *    and define new branches by subject and move the messages     *
  9. *    around.  Because the message number is the label, clicking   *
  10. *    on any thread # or reference # can jump to the referenced    *
  11. *    message                                                      *
  12. *                                                                 *
  13. *    This is for BBS-PC                                           *
  14. *                                                                 *
  15. *   The resultant Thinker document looks like                     *
  16. *                                                                 *
  17. *   (new)New Messages                                             *
  18. *      (36157)Music: date time From:  To:                         *
  19. *         body of message                                         *
  20. *      (36158)JDR - #36139: date time From:  To:                  *
  21. *         body of message                                         *
  22. *                                                                 *
  23. *   Use SORT BRANCH (First Chars) to sort the new messages        *
  24. *   by subject matter.  Add new branches (at the same level as    *
  25. *   "new") for subjects of interest.  Move the messages to these  *
  26. *   subject branches.  When reading the messages follow the       *
  27. *   refereneces by double clicking on the reference numbers or    *
  28. *   follow the threads by clicking on the Reply numbers.          *
  29. *                                                                 *
  30. *   This program can be made to run a lot faster at the cost      *
  31. *   of readability and easy of modification.  The structure       *
  32. *   chosen (SELECT) is very poor for interpreted languages like   *
  33. *   ARexx because it must intepret all the code that is not       *
  34. *   executed in order to find the correct WHEN clause.            *
  35. *   The file MESSAGE1.THNKR runs MUCH faster but it is more       *
  36. *   difficult to understand.   Also deleting the comments will    *
  37. *   help this ARexx program to run faster.                        *
  38. *                                                                 *
  39. ******************************************************************/
  40. trace off
  41. options results
  42.  
  43. /******************************************************************
  44.    First part of setup is to find place to add new messages
  45. ******************************************************************/
  46.  
  47. 'get label first new'       /* test for the branch "new" */
  48. if rc ~= 0 then return 100
  49. 'position save 1'           /* save position of (new) branch */
  50. headlvl='down'              /* first header down from "new" */
  51.  
  52. /******************************************************************
  53.    Now prompt user for the name of the capture file 
  54. ******************************************************************/
  55.  
  56. 'input Enter message file name' /* get name of capture file */
  57. if rc ~= 0 then return rc
  58. file=result
  59. if file='' then return 101
  60. open('msg',file,'read')         /* open the capture file */
  61. if rc = 0 then return 106
  62.  
  63. state=0                         /* looking for message */
  64. statement=''                    /* initialize message body to null */
  65. level='down'                    /* initial level of message body */
  66.  
  67. DO forever                      /* read entire file */
  68.  
  69.     instr=readln('msg')         /* read a line of file */
  70.     if eof('msg') ~= 0 then do  /* hit end of file!! */
  71.         if state = 2 then addtomsgbdy(level,statement) /* finish */
  72.         leave                   /* leave do forever loop */
  73.     end
  74.  
  75.     /****************************************************************
  76.        The variable STATE determines how each line of the capture
  77.        file is processed.  During header processing HEADSTATE determines
  78.        how each line contributes to the header and when the message body
  79.        begins
  80.     ****************************************************************/
  81.  
  82.     SELECT     /* chose STATE action */
  83.  
  84.         WHEN state = 0 then DO              /* looking for message */
  85.  
  86.             /***********************************************************
  87.                 This state (0) only occurs at the beginning before any
  88.                 message headers have been found.
  89.                 It is a convenient place to start 
  90.             ************************************************************/
  91.  
  92.             if ismsg(instr) ~= 0 then do    /* found header */
  93.                 state = 1   
  94.                 number=getnumber(instr)     /* isolate message number */
  95.                 'position restore 1'        /* position to put header */
  96.                 headstate=0                 /* initialize header switch */
  97.                 iterate                     /* go get next line */
  98.             end
  99.         END   /* state = 0 */
  100.  
  101.         WHEN state = 1 then DO   /* process header */
  102.  
  103.             /**********************************************************
  104.                Having found a message header we need to locate the Subject:
  105.                To:/From:  and date.  This section will have to be heavily 
  106.                customized for  each bulletin board system 
  107.             **********************************************************/ 
  108.  
  109.             SELECT  /* chose HEADSTATE action */
  110.  
  111.                 WHEN headstate=0 then DO    /* date on line 2 - BBS-JC */
  112.                     date=space(instr,1)     /* the date info */
  113.                     headstate=1             /* subject */
  114.                     iterate                 /* get next line */
  115.                 end
  116.                 
  117.                 WHEN headstate=1 then DO    /* subject on line 3 -BBS-JC */
  118.                     subject=substr(instr,7)
  119.                     if substr(subject,1,1)='#' then do  /* reference */
  120.                         i=index(subject,' ')-1          /* size of # */  
  121.                         snum=substr(subject,1,i)        /* isolate # */
  122.                         subject=substr(subject,i+4) snum  /* re-arrange */
  123.                     end
  124.                     headstate=2
  125.                     iterate
  126.                 END
  127.  
  128.                 WHEN headstate=2 then DO    /* From: on line 4 - BBS-JC */
  129.                     source=instr
  130.                     headstate=3
  131.                     iterate
  132.                 END
  133.  
  134.                 WHEN headstate=3 then DO    /* To: on line 5 - BBS-JC */
  135.                     head=subject||':' date source substr(instr,3)
  136.  
  137.                     /*************************************************
  138.                         We now have complete header.
  139.                         Add this header and set up for 
  140.                         adding the body of the message subordinate
  141.                         to this header 
  142.                     **************************************************/
  143.  
  144.                     'add after' headlvl '('||number||')'||head /* header */
  145.                     if rc~= 0 then leave
  146.                     headlvl='same'   /* subsequent headers at same level */
  147.                     'position save 1'   /* save position for next header */
  148.                     level='down'        /* insert body as subordinate */
  149.                     statement=''
  150.                     state=2
  151.                     iterate
  152.                 END
  153.  
  154.             END /* select on headstate */
  155.  
  156.         END     /* state = 1 */
  157.  
  158.         WHEN state = 2 then DO   /* process body */
  159.  
  160.             /*******************************************************
  161.                 process body of message.
  162.                 Always be on lookout for beginning of next message 
  163.             *******************************************************/ 
  164.  
  165.             if ismsg(instr) then do     /* end of this message */
  166.                 if addtomsgbdy(level,statement) ~= 0 then leave /*finish */
  167.                 state=1                 /* already found message header */
  168.                 headstate=0             /* begin with first part of hdr */
  169.                 number=getnumber(instr) /* must set up for state 1 */
  170.                 'position restore 1'    /* restore position of header */
  171.                 iterate                 /* start process of header */
  172.             end
  173.  
  174.             /***********************************************************
  175.                 blank lines separate paragraphs (Statements) in the 
  176.                 body of the message.
  177.             ************************************************************/
  178.  
  179.             if instr = '' then do  /* a blank line */
  180.                 if statement ~= '' then do
  181.                     if addtomsgbdy(level,statement) ~= 0 then leave
  182.                     level='same'         /* next statement same level */
  183.                     statement=''
  184.                 end
  185.             end
  186.  
  187.             /*************************************************************
  188.                 If line begins with a blank then add hard carriage return
  189.                 to statement so far (preserve indentation)
  190.                 else just concatenate into one large statement.
  191.             *************************************************************/
  192.  
  193.             else do   /* concatenate lines of statement */
  194.                 if (substr(instr,1,1) = ' ') & (statement ~= '') then
  195.                     statement=statement||'0a'x
  196.                 statement = statement instr
  197.             end
  198.             iterate                     /* next line */
  199.  
  200.         END /* state 2 */
  201.  
  202.     END  /* select on state */
  203.  
  204. END  /* forever reading file */
  205.  
  206. /********************************************************************
  207.     Close the capture file and prompt the user to acknowledge the
  208.     completion of the task so he/she will know when the program is done
  209. *********************************************************************/
  210.  
  211. close('msg')
  212. 'input Acknowledge Completion'
  213. return 'done'    /*  puts "done" on the clipboard */
  214.  
  215. ismsg: procedure    /* see if line is the beginning of a message */
  216.     parse arg str
  217.     if substr(str,1,5) == ' Msg:' then return 1
  218.     else return 0
  219. end
  220.  
  221. getnumber: procedure    /* isolate the message number */
  222.     parse arg str
  223.  
  224.     i=index(str,'#')+1
  225.     j=index(substr(str,i),' ')
  226.     return substr(str,i,j-1)
  227. end
  228.  
  229. addtomsgbdy: procedure  /* add a paragraph (statement) to message */
  230.     parse arg lvl,stmt
  231.     
  232.     if stmt = '' then return 0
  233.     'add after' lvl stmt
  234.     return rc
  235. end
  236.